// pages/getCash /getCash .js
const app = getApp();
var util = require('../../utils/util.js');
Page({
  data: {
    modal: {
      toastHidden: true,
      msg: ""
    },
    bscrdAmount: "",
    bscrdExtracted: "",
    bscrdMobile: "",
    mobileCode: "",
    bscrdAccountName: "",
    bscrdAccountNo: "",
    bscrdBankName: "",
    btnTxt: "提交"
  },
  onLoad: function (options) {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  bindInput(e) {
    // 获取input的值
    if (e.currentTarget.dataset.idx == "amount") {
      this.setData({
        bscrdAmount: e.detail.value
      });
    }
    if (e.currentTarget.dataset.idx == "mobile") {
      this.setData({
        bscrdMobile: e.detail.value
      });
    }
    if (e.currentTarget.dataset.idx == "accountName") {
      this.setData({
        bscrdAccountName: e.detail.value
      });
    }
    if (e.currentTarget.dataset.idx == "accountNo") {
      this.setData({
        bscrdAccountNo: e.detail.value
      });
    }
    if (e.currentTarget.dataset.idx == "bankName") {
      this.setData({
        bscrdBankName: e.detail.value
      });
    }
  },
  bindmMobileCode(e) {
    this.setData({
      mobileCode: e.detail.value
    });
  },
  getCode() {
    var that = this;
    if (this.data.bscrdMobile.length !== 11) {
      util.tipModal(this, "手机格式错误！");
      return;
    }
    var data = {
      crmceUser: app.globalData.userUuid,
      crmceMobile: this.data.bscrdMobile
    }
    util.requestPost("coreShortMessage/apply/cash", data, function (res) {
      if (res.success) {
        util.tipModal(that, "发送成功！");
      } else {
        util.tipModal(that, res.errMsg);
      }
      console.log(res)
    }, function (errData) {
      util.tipModal(that, "获取失败！");
    });
  },
  submitData() {
    var that = this;
    var data = {
      bscrdAmount: that.data.bscrdAmount,
      bscrdExtracted: app.globalData.userUuid,
      bscrdMobile: that.data.bscrdMobile,
      mobileCode: that.data.mobileCode,
      bscrdAccountName: that.data.bscrdAccountName,
      bscrdAccountNo: that.data.bscrdAccountNo,
      bscrdBankName: that.data.bscrdBankNameg
    };
    if (that.data.bscrdAmount = "" || that.data.bscrdMobile == "" || that.data.mobileCode == "" || that.data.bscrdAccountName == "" || that.data.bscrdAccountNo == "" || that.data.bscrdBankNameg == ""){
      util.tipModal(that, "请将内容填写完整！");
      return
    }
    util.requestPost("busiCashRecord/add/busiCashRecord", data, function (res) {
      // console.log(res)
      if (res.success) {
        util.tipModal(that, "提交成功！");
      } else {
        console.log(res)
        util.tipModal(that, res.errMsg);
      }
      that.setData({ "btnTxt": "提交" });
    }, function (errData) {
      util.tipModal(that, "提交失败！");
    });

  },
  toastChange() {
    this.setData({ "modal.toastHidden": true });
  }
})